using FU.Capstones.IMS.Services.Common.DataContracts;
using FU.Capstones.IMS.Services.Common.Respondents;
using FU.Capstones.IMS.Services.DataContracts;

namespace FU.Capstones.IMS.Services.Management
{
    public class Manager
    {
        private readonly Engine engine = new Engine();
        
        #region Account

        //public CollectionFeedback<Account> GetAccountCollection(bool isShowAll)
        //{
        //    return engine.GetAccountCollection(isShowAll);
        //}

        //public SingleFeedback<Account> GetSingleAccount(int accountID)
        //{
        //    return engine.GetSingleAccount(accountID);
        //}

        //public SingleFeedback<int> InsertAccount(Account data)
        //{
        //    Feedback feedback = Validator.Validate(data);
        //    if (!feedback.IsSuccessful)
        //        return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
        //    return engine.InsertAccount(data);
        //}

        //public Feedback UpdateAccount(Account data)
        //{
        //    Feedback feedback = Validator.Validate(data);
        //    if (!feedback.IsSuccessful)
        //        return feedback;
        //    return engine.UpdateAccount(data);
        //}

        //public Feedback DeleteAccount(int objID)
        //{
        //    return engine.DeleteAccount(objID);
        //}

        //public CollectionFeedback<Account> SearchAccount(Account criteria)
        //{
        //    Feedback feedback = Validator.Validate(criteria);
        //    if (!feedback.IsSuccessful)
        //        return (CollectionFeedback<Account>)feedback;
        //    return engine.SearchAccount(criteria);
        //}

        //public Feedback UndoDeleteAccount(int objID)
        //{
        //    return engine.UndoDeleteAccount(objID);
        //}

        public SingleFeedback<Account> Login(Account account)
        {
            Feedback feedback = Validator.Validate(account);
            if (feedback.IsSuccessful)
                return engine.Login(account);
            return (SingleFeedback<Account>) feedback;
        }

        public Feedback CheckIfUsernameExists(string usernameToCheck)
        {
            return engine.CheckIfUsernameExists(usernameToCheck);
        }

        public Feedback ResetPassword(Account account)
        {
            return engine.ResetPassword(account);
        }

        public Feedback ChangePassword(Account account)
        {
            return engine.ChangePassword(account);
        }

        #endregion

        #region Authorization

        public CollectionFeedback<Authorization> GetAuthorizationCollection(bool isShowAll)
        {
            return engine.GetAuthorizationCollection(isShowAll);
        }

        public SingleFeedback<Authorization> GetSingleAuthorization(int objectID)
        {
            return engine.GetSingleAuthorization(objectID);
        }

        public SingleFeedback<int> InsertAuthorization(Authorization data)
        {
            return engine.InsertAuthorization(data);
        }

        public Feedback UpdateAuthorization(Authorization data)
        {
            return engine.UpdateAuthorization(data);
        }

        public Feedback DeleteAuthorization(int objID)
        {
            return engine.DeleteAuthorization(objID);
        }

        public CollectionFeedback<Authorization> SearchAuthorization(Authorization criteria)
        {
            return engine.SearchAuthorization(criteria);
        }

        #endregion

        #region Contact

        public CollectionFeedback<Contact> GetContactCollection(bool isShowAll)
        {
            return engine.GetContactCollection(isShowAll);
        }

        public SingleFeedback<Contact> GetSingleContact(int contactID)
        {
            return engine.GetSingleContact(contactID);
        }

        public SingleFeedback<int> InsertContact(Contact data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
            }
            
            return engine.InsertContact(data);
            
        }

        public Feedback UpdateContact(Contact data)
        {
             Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdateContact(data);    
        }

        public Feedback DeleteContact(int objID)
        {
            return engine.DeleteContact(objID);
        }

        public CollectionFeedback<Contact> SearchContact(Contact criteria)
        {
            return engine.SearchContact(null);
        }

        public Feedback UndoDeleteContact(int objID)
        {
            return engine.UndoDeleteContact(objID);
        }

        #endregion

        #region Employee

        public CollectionFeedback<Employee> GetEmployeeCollection(bool isShowAll)
        {
            return engine.GetEmployeeCollection(isShowAll);
        }

        public SingleFeedback<Employee> GetSingleEmployee(int objectID)
        {
            return engine.GetSingleEmployee(objectID);
        }

        public SingleFeedback<int> InsertEmployee(Employee data)
        {
            Feedback feedback = Validator.Validate(data);
            if (feedback.IsSuccessful)
            {
                return engine.InsertEmployee(data);
            }
            return (SingleFeedback<int>) feedback;
        }

        public Feedback UpdateEmployee(Employee data)
        {
            Feedback feedback = Validator.Validate(data);
            if (feedback.IsSuccessful)
            {
                return engine.UpdateEmployee(data);
            }
            return feedback;
        }

        public Feedback DeleteEmployee(int objID)
        {
            return engine.DeleteEmployee(objID);
        }

        public CollectionFeedback<Employee> SearchEmployee(EmployeeCriteria criteria)
        {
            return engine.SearchEmployee(criteria);    
            
        }

        public Feedback UndoDeleteEmployee(int objID)
        {
            return engine.UndoDeleteEmployee(objID);
        }

        #endregion

        #region EmploymentType

        public CollectionFeedback<EmploymentType> GetEmploymentTypeCollection(bool isShowAll)
        {
            return engine.GetEmploymentTypeCollection(isShowAll);
        }

        public SingleFeedback<EmploymentType> GetSingleEmploymentType(int employmentTypeID)
        {
            return engine.GetSingleEmploymentType(employmentTypeID);
        }

        public SingleFeedback<int> InsertEmploymentType(EmploymentType data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return (SingleFeedback<int>) feedback;
            }
            return engine.InsertEmploymentType(data);
        }

        public Feedback UpdateEmploymentType(EmploymentType data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdateEmploymentType(data);
        }

        public Feedback DeleteEmploymentType(int objID)
        {
            return engine.DeleteEmploymentType(objID);
        }

        public CollectionFeedback<EmploymentType> SearchEmploymentType(EmploymentType criteria)
        {
            return engine.SearchEmploymentType(criteria);
        }

        public Feedback UndoDeleteEmploymentType(int objID)
        {
            return engine.UndoDeleteEmploymentType(objID);
        }

        #endregion

        #region Material

        public CollectionFeedback<Material> GetMaterialCollection(bool isShowAll)
        {
            return engine.GetMaterialCollection(isShowAll);
        }

        public CollectionFeedback<Material> GetMaterialCollectionType(bool isShowAll)
        {
            return engine.GetMaterialCollectionType(isShowAll);
        }

        public SingleFeedback<Material> GetSingleMaterial(int materialID)
        {
            return engine.GetSingleMaterial(materialID);
        }

        public SingleFeedback<int> InsertMaterial(Material data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
            }
            return engine.InsertMaterial(data);
        }

        public Feedback UpdateMaterial(Material data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdateMaterial(data);
        }

        public Feedback DeleteMaterial(int objID)
        {
            return engine.DeleteMaterial(objID);
        }

        public CollectionFeedback<Material> SearchMaterial(MaterialCriteria criteria)
        {
            return engine.SearchMaterial(criteria);
        }

        public Feedback UndoDeleteMaterial(int objID)
        {
            return engine.UndoDeleteMaterial(objID);
        }

        #endregion

        #region Order

        public CollectionFeedback<Order> GetOrderCollection(bool isShowAll)
        {
            return engine.GetOrderCollection(isShowAll);
        }
        public CollectionFeedback<Order> GetOrderCollectionByParameter(bool? isMaterial)
        {
            return engine.GetOrderCollectionByParameter(isMaterial);
        }

        public SingleFeedback<Order> GetSingleOrder(int orderID)
        {
            return engine.GetSingleOrder(orderID);
        }

        public SingleFeedback<int> InsertOrder(Order data)
        {
            return engine.InsertOrder(data);
        }

        public Feedback UpdateOrder(Order data)
        {
            return engine.UpdateOrder(data);
        }

        public Feedback DeleteOrder(int objID)
        {
            return engine.DeleteOrder(objID);
        }

        public CollectionFeedback<Order> SearchOrder(OrderCriteria criteria)
        {
            return engine.SearchOrder(criteria);
        }

        public Feedback UndoDeleteOrder(int objID)
        {
            return engine.UndoDeleteOrder(objID);
        }

        #endregion

        #region Partner

        public CollectionFeedback<Partner> GetPartnerCollection(bool isShowAll)
        {
            return engine.GetPartnerCollection(isShowAll);
        }

        public CollectionFeedback<Partner> GetPartnerCollectionByParam(bool? isSupplier)
        {
            return engine.GetPartnerCollectionByParam(isSupplier);
        }

        public SingleFeedback<Partner> GetSinglePartner(int partnerID)
        {
            return engine.GetSinglePartner(partnerID);
        }

        public SingleFeedback<int> InsertPartner(Partner data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
            }
            return engine.InsertPartner(data);    
        }

        public Feedback UpdatePartner(Partner data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdatePartner(data);
        }

        public Feedback DeletePartner(int objID)
        {
            return engine.DeletePartner(objID);
        }

        public CollectionFeedback<Partner> SearchPartner(Partner criteria)
        {
            return engine.SearchPartner(criteria);
        }

        public Feedback UndoDeletePartner(int objID)
        {
            return engine.UndoDeletePartner(objID);
        }

        #endregion

        #region Product

        public CollectionFeedback<Product> GetProductCollection(bool isShowAll)
        {
            return engine.GetProductCollection(isShowAll);
        }

        public CollectionFeedback<Product> GetProductCollectionType(bool isShowAll)
        {
            return engine.GetProductCollectionType(isShowAll);
        }

        public SingleFeedback<Product> GetSingleProduct(int productID)
        {
            return engine.GetSingleProduct(productID);
        }

        public SingleFeedback<int> InsertProduct(Product data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
            }
            return engine.InsertProduct(data);
        }

        public Feedback InsertBuiltupMaterial(int pID, int mID, long mQuantity)
        {
            return engine.InsertBuiltupMaterial(pID, mID, mQuantity);
        }

        public Feedback UpdateProduct(Product data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdateProduct(data);
        }

        public Feedback DeleteProduct(int objID)
        {
            return engine.DeleteProduct(objID);
        }

        public Feedback DeleteBuiltup(int pID,int mID)
        {
            return engine.DeleteBuiltup(pID,mID);
        }

        public CollectionFeedback<Product> SearchProduct(ProductCriteria criteria)
        {
            return engine.SearchProduct(criteria);
        }

        public Feedback UndoDeleteProduct(int objID)
        {
            return engine.UndoDeleteProduct(objID);
        }

        #endregion

        #region Role

        public CollectionFeedback<Role> GetRoleCollection(bool isShowAll)
        {
            return engine.GetRoleCollection(isShowAll);
        }

        public SingleFeedback<Role> GetSingleRole(int roleID)
        {
            return engine.GetSingleRole(roleID);
        }

        public SingleFeedback<int> InsertRole(Role data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
            }
            return engine.InsertRole(data);
        }

        public Feedback UpdateRole(Role data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdateRole(data);
        }

        public Feedback DeleteRole(int objID)
        {
            return engine.DeleteRole(objID);
        }

        public CollectionFeedback<Role> SearchRole(Role criteria)
        {
            return engine.SearchRole(criteria);
        }

        public Feedback UndoDeleteRole(int objID)
        {
            return engine.UndoDeleteRole(objID);
        }

        #endregion

        #region Warehouse

        public CollectionFeedback<Warehouse> GetWarehouseCollection(bool isShowAll)
        {
            return engine.GetWarehouseCollection(isShowAll);
        }

        public SingleFeedback<Warehouse> GetSingleWarehouse(int warehouseID)
        {
            return engine.GetSingleWarehouse(warehouseID);
        }

        public SingleFeedback<int> InsertWarehouse(Warehouse data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return new SingleFeedback<int>(feedback.Message, feedback.IsSuccessful, -1);
            }
            return engine.InsertWarehouse(data);
        }

        public Feedback UpdateWarehouse(Warehouse data)
        {
            Feedback feedback = Validator.Validate(data);
            if (!feedback.IsSuccessful)
            {
                return feedback;
            }
            return engine.UpdateWarehouse(data);
        }

        public Feedback DeleteWarehouse(int objID)
        {
            return engine.DeleteWarehouse(objID);
        }

        public CollectionFeedback<Warehouse> SearchWarehouse(Warehouse criteria)
        {
            return engine.SearchWarehouse(criteria);
        }

        public Feedback UndoDeleteWarehouse(int objID)
        {
            return engine.UndoDeleteWarehouse(objID);
        }

        #endregion

        #region MaterialLoaf

        public CollectionFeedback<MaterialLoaf> GetMaterialLoafCollection(bool isShowAll)
        {
            return engine.GetMaterialLoafCollection(isShowAll);
        }

        public SingleFeedback<MaterialLoaf> GetSingleMaterialLoaf(int materialID)
        {
            return engine.GetSingleMaterialLoaf(materialID);
        }

        public SingleFeedback<int> InsertMaterialLoaf(MaterialLoaf data)
        {
            return engine.InsertMaterialLoaf(data);
        }

        public Feedback UpdateMaterialLoaf(MaterialLoaf data)
        {
            return engine.UpdateMaterialLoaf(data);
        }

        public Feedback DeleteMaterialLoaf(int data)
        {
            return engine.DeleteMaterialLoaf(data);
        }

        public CollectionFeedback<MaterialLoaf> SearchMaterialLoaf(MaterialLoaf criteria)
        {
            return engine.SearchMaterialLoaf(criteria);
        }

        public Feedback UndoDeleteMaterialLoaf(int data)
        {
            return engine.UndoDeleteMaterialLoaf(data);
        }

        #endregion

    }
}
